<template>
	<view class="content">
		<view class="view1">
			<view style="margin-left: 35%;padding-top: 70upx;font-size: 29px;color: #FFFFFF;font-weight: 400;">¥ {{ money }}</view>
			<view style="display: flex;flex-direction: row;justify-content: space-around;margin-top: 30upx;" v-if="isShow">
				
				<view class="item-wrap">
					<view class="item-title">总收入</view>
					<view class="item-title item-money" v-if="isMall">¥{{ totalMoney }}</view>
					<view class="item-title item-money" v-else>¥{{ money }}</view>
				</view>
				<view class="item-wrap">
					<view class="item-title">可提现金额</view>
					<view class="item-title item-money" v-if="isMall">¥{{ balance }}</view>
					<view class="item-title item-money" v-else>¥{{ mayMoney }}</view>
				</view>
				<view class="item-wrap">
					<view class="item-title">冻结金额</view>
					<view class="item-title item-money" v-if="isMall">¥{{ frozenAmount }}</view>
					<view class="item-title item-money" v-else>¥{{ cannotMoney }}</view>
				</view>
				<view class="item-wrap">
					<view class="item-title">积分</view>
					<view class="item-title item-money" v-if="isMall">¥{{ integralMoney }}</view>
					<view class="item-title item-money" v-else>¥{{ integralMoney }}</view>
				</view>
				<!-- <view style="width: 20%; margin: 70upx 0 0 50upx;text-align: center;">
					<view style="font-size: 16px;color: #FFFFFF;">总收入</view>
					<view v-if="isMall" style="font-size: 14px;color: #FFFFFF; margin-top: 10upx;">¥{{ totalMoney }}</view>
					<view v-else style="font-size: 14px;color: #FFFFFF; margin-top: 10upx;">¥{{ money }}</view>
				</view>
				<view style="background-color: #FFFFFF;width: 1upx; height: 70upx;margin: 70upx 0 0 0;"></view>
				<view style="width: 30%; margin: 70upx 0 0 50upx;text-align: center;">
					<view style="font-size: 16px;color: #FFFFFF;">可提现金额</view>
					<view v-if="isMall" style="font-size: 14px;color: #FFFFFF; margin-top: 10upx;">¥{{ balance }}</view>
					<view v-else style="font-size: 14px;color: #FFFFFF; margin-top: 10upx;">¥{{ mayMoney }}</view>
				</view>
				<view style="background-color: #FFFFFF;width: 1upx; height: 70upx;margin: 70upx 0 0 70upx;"></view>
				<view style="width: 30%; margin: 70upx 0 0 100upx;text-align: center;">
					<view style="font-size: 16px;color: #FFFFFF;">冻结金额</view>
					<view v-if="isMall" style="font-size: 14px;color: #FFFFFF; margin-top: 10upx;">¥{{ frozenAmount }}</view>
					<view v-else style="font-size: 14px;color: #FFFFFF; margin-top: 10upx;">¥{{ cannotMoney }}</view>
				</view> -->
			</view>
		</view>

		<view class="view2">
			<!-- <view class="view2-view" @click="goRecharge">
				<image src="../../static/img/wallet/recharge.jpg" class="view2-view-image"></image>
				<view class="view2-view1">
					<view class="view2-view-text">充值</view>
					<image src="../../static/img/right_icon.png" class="view2-view-image-right"></image>
				</view>
			</view> -->
			<view class="view2-view" @tap="goCash">
				<image src="../../static/img/wallet/recharge.jpg" class="view2-view-image"></image>
				<view class="view2-view1">
					<view class="view2-view-text">提现</view>
					<image src="../../static/img/right_icon.png" class="view2-view-image-right"></image>
				</view>
			</view>
			<view class="view2-view" @tap="trans">
				<image src="../../static/img/wallet/recharge.jpg" class="view2-view-image"></image>
				<view class="view2-view1">
					<view class="view2-view-text">转账</view>
					<image src="../../static/img/right_icon.png" class="view2-view-image-right"></image>
				</view>
			</view>
			<view class="view2-view" @tap="detail">
				<image src="../../static/img/wallet/recharge.jpg" class="view2-view-image"></image>
				<view class="view2-view1">
					<view class="view2-view-text">资金明细</view>
					<image src="../../static/img/right_icon.png" class="view2-view-image-right"></image>
				</view>
			</view>
			<view class="view2-view" @tap="frozenDetail">
				<image src="../../static/img/wallet/recharge.jpg" class="view2-view-image"></image>
				<view class="view2-view1">
					<view class="view2-view-text">冻结明细</view>
					<image src="../../static/img/right_icon.png" class="view2-view-image-right"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from '../../../common/config.js'
	export default {
		data() {
			return {
				cannotMoney: 0,
				mayMoney: 0,
				money:0, // 总金额
				balance:0, // 可提现金额
				totalMoney:0, // 总收入
				frozenAmount:0, // 冻结金额
				integralMoney:0, // 积分
				from:'',
				userId:'',
				isShow:true,
				isMall:false,
			};
		},
		onShow() {
			let userId = this.$queue.getData('userId');
			this.userId =userId
			if("mall"==this.from){
				this.getMyInfo()
				this.isMall = true
			}
			if (userId) {
				this.getUserMoney(userId);
			}
		},
		onLoad(options) {
			this.from = options.from
			let userId = this.$queue.getData('userId');
			if (userId) {
				this.getUserMoney(userId);
			}
		},
		methods: {
			getMyInfo(){
				console.log('userid:'+this.userId)
				uni.request({
					// url:'https://k999az04ootw.ngrok2.xiaomiqiu.cn/p/user/newUserInfo/'+this.userId,
					url:config.mallHost+'/p/user/newUserInfo/'+this.userId,
					method:'GET',
					success: (res) => {
						console.log('个人信息',res)
						this.totalMoney = res.data.totalMoney
						this.money = res.data.money
						this.balance = res.data.balance
						this.frozenAmount = res.data.frozenAmount
						this.integralMoney = res.data.integralMoney
					},
					fail: (err) => {
						console.log('err',err)
					}
				})
			},
			goCash() {
				uni.navigateTo({
					url: '../member/cash?from='+this.from
				});
			},
			//转账
			trans() {
				uni.navigateTo({
					url: '../task/transfer?from='+this.from
				});
			},
			goRecharge() {
				uni.navigateTo({
					url: '../task/recharge?from='+this.from
				});
			},
			detail: function() {
				uni.navigateTo({
					url: './moneydetails?from='+this.from
				});
			},
			frozenDetail: function() {
				uni.navigateTo({
					url: './frozendetails?from='+this.from
				});
			},
			getUserMoney(userId) {
				this.$Request.getT('userMoney/selectUserMoney?userId=' + userId).then(res => {
					if (res.code === 0) {
						this.mayMoney = res.data.mayMoney;
						this.cannotMoney = res.data.cannotMoney;
						this.money = (Number(this.mayMoney)+Number(this.cannotMoney)).toFixed(2);
					}
				});
			},
			getOut() {
				let that = this;
				let token = this.$queue.getData('token');
				let userId = this.$queue.getData('userId');
				if (token) {
					if (that.zhifubao && that.zhifubaoName) {
						if (parseFloat(this.money).toFixed(1) >= 10) {
							uni.showModal({
								title: '提现申请提示',
								content: '请仔细确认收款人信息\n\n姓名:' + that.zhifubaoName + '\n\n收款账号：' + that.zhifubao + '',
								success: e => {
									if (e.confirm) {
										this.$queue.showLoading('提现中...');
										this.$Request.getT('/cash/out/' + userId).then(res => {
											if (res.status === 0 && res.data) {
												that.$queue.showToast('提现申请成功，预计三个工作日到账');
												that.getMoney();
											}
											uni.hideLoading();
										});
									}
								}
							});
						} else {
							this.$queue.showToast('提现金额必须大于或等于10元才可提现');
						}
					} else {
						uni.navigateTo({
							url: '/package-task/pages/member/zhifubao'
						});
					}
				} else {
					uni.navigateTo({
						url: '/package-task/pages/public/login'
					});
				}
			}
		}
	};
</script>

<style>
	.view1 {
		width: 100%;
		height: 375upx;
		/* background-image: url(../../static/img/my/wallet/backgroudColor.png); */
		background: #ff580b;
		background-size: 100%;
	}

	.view2 {
		background-color: #ffffff;
		width: 100%;
		/* height: 400upx; */
		margin-top: 20upx;
	}

	.view2-view {
		display: flex;
		flex-direction: row;
		width: 100%;
		height: 100upx;
		align-items: center;
	}

	.view2-view1 {
		display: flex;
		flex-direction: row;
		width: 90%;
		align-items: center;
	}

	.view2-view-image {
		margin-left: 40upx;
		width: 50upx;
		height: 50upx;
	}

	.view2-view-text {
		font-size: 14px;
		color: #000000;
		margin-left: 20upx;
		width: 80%;
	}

	.view2-view-image-right {
		width: 18upx;
		height: 20upx;
		margin-left: 50upx;
	}
	.view1 .item-wrap{
		text-align: center;
	}
	.view1 .item-title{
		font-size: 32upx;
		color: white;
	}
	.view1 .item-money{
		margin-top: 10upx;
	}
</style>
